package leetcode.easy;

/**
 * ClassName: $121_MaxProfit
 * Description:
 * date: 2022-02-11 21:47
 *
 * @author liyifan
 */
public class $121_MaxProfit {
    public int maxProfit(int[] prices) {
        int minPrice = Integer.MAX_VALUE;
        int maxProfit = 0;
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] < minPrice) {
                minPrice = prices[i];
            } else {
                maxProfit = Math.max(maxProfit, prices[i] - minPrice);
            }
        }
        return maxProfit;

    }
}
